<template>
	<view class="">
		<view class="cate-image">
			<image src="https://cs.b2c.niuteam.cn/upload/uniapp/giftcard/detail/giftcard2.png" mode=""></image>
		</view>
		<view class="cate-search">
			<view class="search-box">
				<input class="uni-input" placeholder="请输入兑换码" :value="cardNum" @input="onInput" />
			</view>
		</view>
		
		<view class="exchange-btn">
			<button type="primary" @click="exchange()">立即兑换</button>
		</view>
		<view class="exchange-list" @click="gotoexchange()">我的兑换列表</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {	
				cardNum: ''
			};
		},
		onShow() {
			// 刷新多语言
			this.$langConfig.refresh();
		},
		methods: {
			onInput(e) {
				const { value } = e.target;
				this.cardNum = value
			},
			gotoexchange() {
				this.$util.redirectTo('/promotionpages/giftcard/my_exchange/exchange_list');
			},
			exchange() {
				this.$api.sendRequest({
					url: '/giftcard/api/giftcard/exchange',
					data: {
						carmichael_text: this.cardNum
					},
					success: res => {
						if (res.code == 0 && res.data) {
							this.$util.showToast({
									title: res.message
								});
							this.cardNum='';
						} else {
							this.$util.showToast({
									title: res.message
								});
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						mescroll.endErr();
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
		},
	};
</script>

<style lang="scss">
	.cate-image{
		display: flex;
		image{
			width: 170rpx;
			height: 116rpx;
			margin:274rpx auto 100rpx auto;
		}
	}
	.cate-search {
		// margin-top: 399rpx;
		width: 100%;
		height: 80rpx;
		padding: 10rpx 30rpx;
		box-sizing: border-box;
		/* #ifdef H5 */
		padding-top: 30rpx;
		/* #endif */

		input {
			font-size: $font-size-base;
			height: 80rpx;
			padding: 15rpx 25rpx 15rpx 30rpx;
			line-height: 60rpx;
			width: calc(100% - 120rpx);
		}

		.search-box {
			width: 100%;
			background: #fff;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 20rpx;
		}
		
		.input-placeholder {
			text-align: center;
		}
	}

	.exchange-btn {
		margin: 200rpx 0 0 0;

	}
	
	.exchange-list {
		color: #808080;
		margin: 20rpx 0 0 520rpx;
	}
</style>
